﻿using static CoreWebApiNuGet.ApiContracts.ApiResults;

namespace CoreWebApiNuGet.ApiContracts
{
    /// <summary>
    /// 异常处理中间件
    /// </summary>
    public class ApiException : Exception
    {
        public BaseResultMsg BaseResultMsg { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="baseResultMsg"></param>
        /// <param name="innerException"></param>
        public ApiException(BaseResultMsg baseResultMsg , Exception innerException = null)
             : base(baseResultMsg.ResultMsgs, innerException)
        {
            if (baseResultMsg == null)
            {
                throw new ArgumentNullException("errorResult");
            }

            BaseResultMsg = baseResultMsg;
            base.Data.Add("ErrorResult", BaseResultMsg);
        }
    }
}
